//
//  LDYStatusRetweetView.swift
//  李东阳微博
//
//  Created by 李东阳 on 16/4/21.
//  Copyright © 2016年 李东阳. All rights reserved.
//

import UIKit
import SnapKit

class LDYStatusRetweetView: UIView {

    // 记录我们转发微博的底部约束
    var retweetViewConstraint: Constraint?

    var status:LDYStatus?{
        didSet{
        
            self.retweetViewConstraint?.uninstall()
            
        retweetLabel.text = status?.retweeted_status?.text
        
                         //MARK: -  有转发微博配图

            if status?.retweeted_status?.pic_urls?.count != 0{
            
                pictureView.picInfo = status?.retweeted_status?.pic_urls
                
              self.snp_makeConstraints(closure: { (make) -> Void in
                
                 self.retweetViewConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
              })
            
                // 03 显示配图
                pictureView.hidden = false
            }else{
            
                self.snp_makeConstraints(closure: { (make) -> Void in
                    
                    self.retweetViewConstraint = make.bottom.equalTo(retweetLabel).offset(10).constraint
                })
                
                // 03 显示配图
                pictureView.hidden = true
            }



        }
    }
    
    
    override init(frame: CGRect) {
        "TODO:|FIXME: 转发微博*********************"
        super.init(frame: frame)
        setupUI()
        
     
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

        //MARK: -  设置视图
    private func setupUI(){
    
   self.backgroundColor = RGB(red: 237, green: 237, blue: 237)
            //MARK: -  添加控件
       addSubview(retweetLabel)
       addSubview(pictureView)
            //MARK: -   设置约束
        retweetLabel.snp_makeConstraints { (make) -> Void in
            
            make.leading.top.trailing.equalTo(self).offset(10)
    
        }
        
        
        pictureView.snp_makeConstraints { (make) -> Void in
            // make.size.equalTo(CGSize(width: 100, height: 100))
            make.top.equalTo(retweetLabel.snp_bottom).offset(10)
            make.leading.equalTo(retweetLabel)
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
            self.retweetViewConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(10).constraint
        }
        

  
    }
   
        //MARK: -  转发微博正文
    private lazy var retweetLabel: UILabel = {
    
    let lab = UILabel(textColor: UIColor.blackColor(), textFont: 14)
        
    lab.numberOfLines = 0
     return lab
        
    }()
 
        //MARK: -  转发微博配图
    private lazy var pictureView:LDYstatusPictureView = LDYstatusPictureView()
    
}
